<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$item=$worker;
	unset($item['password']);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'助理名称','name'=>'title', 'help'=>''),
					array('name'=>'username','title'=>'用户名','type'=>'string'),
					array('name'=>'password','title'=>'密码','type'=>'password'),
					array('type'=>'text','title'=>'描述','name'=>'desc', 'help'=>''),
					array('type'=>'image','title'=>'头像','name'=>'image', 'help'=>''),
					array('type'=>'choose','title'=>'绑定会员','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
				)
			),
		)
	);
	$return['on_days']=array('0'=>'周日','1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六');
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写助理名称！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'desc'=>trim($postdata['desc']),
		'image'=>trim($postdata['image']),
		'username'=>trim($postdata['username']),
		'status'=>trim($postdata['status'])
	);
	if($data['password']){
		$data['password']=base64_encode($data['password']);
	}
	if($data['username']){
		$uname=pdo_get('jy_yiliao_worker_zhuli',array('username'=>$data['username'],'uniacid'=>$_SESSION['uniacid']));
	}
	$id=intval($postdata['id']);
	if($uname && $uname['id']!=$id){
		exi('账号不可以重复','error');	
	}
	if($id){
		pdo_update('jy_yiliao_worker_zhuli',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('助理修改成功！','','list');
	}else{
		if(!$postdata['username'] || !$postdata['password']){
			exi('请填写账户和密码！','error');
		}
		$data['workerid']=$this->worker_id;
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_yiliao_worker_zhuli',$data);
		exi('助理增加成功！','','list');
	}
}